package com.uenpay.oem.ui.trans.paycode;

import android.graphics.Bitmap;

import com.google.zxing.WriterException;
import com.uenpay.im.zxing.encoding.EncodingHandler;
import com.uenpay.oem.common.AppConstant;
import com.uenpay.oem.data.modelImpl.BankCardModel;
import com.uenpay.oem.data.modelImpl.TransactionModel;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.service.bean.TransBankCardList;
import com.uenpay.service.model.IBankCardModel;
import com.uenpay.util.net.listener.HttpOnNextListener;

/**
 * Author: liulou
 * Date: 2017/7/4.
 * desc:
 */

public class PayCodePresenter implements PayCodeContract.Presenter {

    private PayCodeContract.View mView;
    private IBankCardModel mBankCardModel;

    public PayCodePresenter(PayCodeContract.View view) {
        this.mView = view;
        mBankCardModel = new BankCardModel();
    }

    @Override
    public void getQrCode(final String url, final int widthAndHeight) {
        try {
            Bitmap qrCode = EncodingHandler.createQRCode(url.replace("\n", ""), widthAndHeight);
            if (qrCode != null) {
                mView.showQrCode(qrCode);
            }
        } catch (WriterException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void getTransBankCardList() {
        mBankCardModel.getTransBankList(AppConstant.TradeType.CHARHE, new HttpOnNextListener<TransBankCardList<BankCardInfo>>() {
            @Override
            public void onNext(TransBankCardList<BankCardInfo> bankCardList) {
                mView.setTransBankCardList(bankCardList);
            }
        });
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }
}
